package com.liugl.uiwidgettest

import android.app.AlertDialog
import android.content.Intent
import android.os.Bundle
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*
import utils.L

class MainActivity : BasicActivity(), View.OnClickListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        bt1.setOnClickListener(this)
        bt2.setOnClickListener(this)
        im.setOnClickListener(this)
        im2.setOnClickListener(this)
        showD.setOnClickListener(this)
        ui.setOnClickListener(this)
        list.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        when (v) {
            bt1 -> L.d("${et.text}")
            bt2 -> {
                et.text.clear()
                val intent = Intent(this, RelativeActivity::class.java)
                startActivity(intent)
            }
            im -> im.setImageResource(R.drawable.img_2)
            im2 -> {
                if (pb.progress >= 100) {
                    pb.progress = 0
                } else {
                    pb.progress += 10
                }
            }
            showD -> {
                AlertDialog.Builder(this).apply {
                    setTitle("This is AlerDialog")
                    setMessage("Something show here")
                    setCancelable(false)
                    setPositiveButton("OK") { _, _ -> }
                    setNegativeButton("Cancel") { _, _ -> }
                    show()
                }
            }
            ui -> {
                val intent = Intent(this, CustomWidget::class.java)
                startActivity(intent)
            }
            list -> {
                val intent = Intent(this, ListActivity::class.java)
                startActivity(intent)
            }
        }
    }
}